<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('【请填写功能名称】列表')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-editable-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li class="select-time">
                                <label>订单日期：</label>
                                <input style="width: 200px;" type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginDdate]" data-format="yyyy-MM-dd HH:mm:ss"/>
                                <span>-</span>
                                <input style="width: 200px;" type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endDdate]" data-format="yyyy-MM-dd HH:mm:ss"/>
                            </li>
                            <li>
                                <label>单号：</label>
                                <input type="text" name="code"/>
                            </li>
                            <li>
                                <label>单据类型：</label>
                                <select name="ctype" >
                                    <option value="">所有</option>
                                    <option value="订货">订货</option>
                                    <option value="退货">退货</option>
                                </select>
                            </li>
                            <li class="select-selectpicker">
                                <label>订单状态：</label>
                                <select id="st" name="st" class="selectpicker show-tick form-control" multiple data-live-search="false">
                                    <option value="">所有</option>
                                    <option value="保存">保存</option>
                                    <option value="审核">审核</option>
                                    <option value="发货中">发货中</option>
                                    <option value="发货完成">发货完成</option>
                                    <option value="收货完成">收货完成</option>
                                    <option value="关闭">关闭</option>
                                </select>
                            </li>
                            <li>
                                <label>物流单号：</label>
                                <input type="text" name="logcode"/>
                            </li>
                            <li>
                                <label>门店：</label>
                                <input type="text" name="shopname"/>
                            </li>
                            <li>
                                <label>调出仓库：</label>
                                <input type="text" name="fromwhname"/>
                            </li>
                            <li>
                                <label>调入仓库：</label>
                                <input type="text" name="towhname"/>
                            </li>
                            <li>
                                <label>物流单号：</label>
                                <input type="text" name="logcode"/>
                            </li>
                            <li>
                                <label>打单人员：</label>
                                <input type="text" name="emp"/>
                            </li>
                            <li>
                                <label>审核人：</label>
                                <input type="text" name="creditemp"/>
                            </li>
                            <li>
                                <label>发货人：</label>
                                <input type="text" name="sendemp"/>
                            </li>
                            <li>
                                <label>接受人：</label>
                                <input type="text" name="recemp"/>
                            </li>
                            <li>
                                <label>备注：</label>
                                <input type="text" name="memo"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
<!--                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="erp:so:add">
                    <i class="fa fa-plus"></i> 添加
                </a>-->
               <!-- <a class="btn btn-success" onclick="review();" >
                    <i class="fa fa-plus"></i> 审核
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="erp:so:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="erp:so:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>-->
               <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="erp:so:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: datetimepicker-js" />
     <th:block th:include="include :: bootstrap-table-editable-js" />
     <th:block th:include="include :: bootstrap-select-js" />
     <th:block th:include="include :: jquery-cxselect-js" />
    <!--<script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('erp:so:edit')}]];
        var removeFlag = [[${@permission.hasPermi('erp:so:remove')}]];
        var prefix = ctx + "erp/so";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "【请填写功能名称】",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'ddate', 
                    title: '订单日期'
                },
                {
                    field: 'code', 
                    title: '单号'
                },
                {
                    field: 'ctype', 
                    title: '单据类型'
                },
                {
                    field: 'st', 
                    title: '订单状态'
                },
                {
                    field: 'logcode', 
                    title: '物料单号'
                },
                {
                    field: 'sysdt', 
                    title: '制单时间'
                },
                {
                    field: 'emp', 
                    title: '打单人员'
                },
                {
                    field: 'creditemp', 
                    title: '审核人'
                },
                {
                    field: 'creditdt', 
                    title: '审核时间'
                },
                {
                    field: 'sendemp', 
                    title: '发货人'
                },
                {
                    field: 'senddt', 
                    title: '发货时间'
                },
                {
                    field: 'recemp', 
                    title: '接受人'
                },
                {
                    field: 'recdt', 
                    title: '接受时间'
                },
                {
                    field: 'memo', 
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
     </script>-->

     <script th:inline="javascript">

         /*$('.time-input').datetimepicker({
             format: 'yyyy-MM-dd HH:mm:ss',
             autoclose: true,
             minView: 0,
             minuteStep:1
         });*/

        // var editFlag = [[${@permission.hasPermi('erp:so:edit')}]];
         var removeFlag = [[${@permission.hasPermi('erp:so:remove')}]];
         var prefix = ctx + "erp/so";
        // var datas = [[${@dict.getType('sys_normal_disable')}]];

         $(function() {
             var options = {
                 url: prefix + "/list",
                 createUrl: prefix + "/add",
                 updateUrl: prefix + "/editSos/{id}",
                 // updateSo: prefix + "/edit/{id}",
                 removeUrl: prefix + "/remove",
                 exportUrl: prefix + "/exportAll",
                 modalName: "订单信息",
                 showSearch: false,
                 showRefresh: false,
                 showToggle: false,
                 showColumns: false,
                 detailView: true,
                 uniqueId: "id",
                 onExpandRow : function(index, row, $detail) {
                     initChildTable(index, row, $detail);
                 },
                 columns: [{
                     checkbox: true
                 }
                     ,
                     {
                         field: 'id',
                         title: '主键',
                         formatter: function(value, row, index) {
                               return value.toString();
                         }
                     }
                     ,
                     {
                         field: 'ddate',
                         title: '订单日期'
                     },
                     {
                         field: 'code',
                         title: '单号'
                     },
                     {
                         field: 'ctype',
                         title: '单据类型'
                     },
                     {
                         field: 'st',
                         title: '订单状态'
                     },
                     {
                         field: 'shopname',
                         title: '门店'
                     },
                     {
                         field: 'fromwhname',
                         title: '调出仓库'
                     },
                     {
                         field: 'towhname',
                         title: '调入仓库'
                     },
                     {
                         field: 'sysdt',
                         title: '制单时间'
                     },
                     {
                         field: 'emp',
                         title: '打单人员'
                     },
                     {
                         field: 'creditemp',
                         title: '审核人'
                     },
                     {
                         field: 'creditdt',
                         title: '审核时间'
                     },
                     {
                         field: 'sendemp',
                         title: '发货人'
                     },
                     {
                         field: 'senddt',
                         title: '发货时间'
                     },
                     {
                         field: 'recemp',
                         title: '接受人'
                     },
                     {
                         field: 'recdt',
                         title: '接受时间'
                     },
                    /* {
                         field: 'isreplace',
                         title: '是否厂家代发'
                     },*/
                     {
                         field: 'memo',
                         title: '备注'
                     },

                     {
                         title: '操作',
                         align: 'center',
                         formatter: function(value, row, index) {
                             debugger;
                             var actions = [];
                             actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="closeso(\'' + row.id + '\')"><i class="fa fa-edit"></i>关闭订单</a> ');
                             if(row.st == "关闭"){
                                 actions.push('<a class="btn btn-warning btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="openso(\'' + row.id + '\')"><i class="fa fa-edit"></i>撤销关闭</a> ');
                                 return actions.join('');
                             }else{

                                 if(row.ctype == "退货"){
                                     actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.editSo(\'11' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                     if(row.st == "审核"){
                                         actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="disReview(\'' + row.id + '\')"><i class="fa fa-edit"></i>撤销审核</a> ');
                                     }else{
                                         actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="review(\'' + row.id + '\')"><i class="fa fa-edit"></i>审核</a> ');
                                         actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="batchUpdate(\'' + row.id + '\')"><i class="fa fa-edit"></i>批量修改发货数量</a> ');
                                     }
                                 }else {
                                     actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.editSo(\'11' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                     if(row.st == "审核"){
                                         actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="disReview(\'' + row.id + '\')"><i class="fa fa-edit"></i>撤销审核</a> ');
                                         actions.push('<a class="btn btn-warning btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="senditem(\'' + row.id + '\')"><i class="fa fa-edit"></i>确认发货</a>');
                                         actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="batchUpdate(\'' + row.id + '\')"><i class="fa fa-edit"></i>批量修改发货数量</a> ');
                                     }else if(row.st == "发货中"){
                                         actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="disReview(\'' + row.id + '\')"><i class="fa fa-edit"></i>撤销审核</a> ');
                                         actions.push('<a class="btn btn-warning btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="batchUpdate(\'' + row.id + '\')"><i class="fa fa-edit"></i>批量修改发货数量</a> ');
                                         actions.push('<a class="btn btn-info btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="viewSosSend(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看发货记录</a> ');
                                     }else if(row.st == "保存"){
                                         actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="review(\'' + row.id + '\')"><i class="fa fa-edit"></i>审核</a> ');
                                         actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="batchUpdate(\'' + row.id + '\')"><i class="fa fa-edit"></i>批量修改发货数量</a> ');
                                     }else if(row.st == "发货完成"){
                                         actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="viewSosSend(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看发货记录</a> ');
                                     }

                                 }
                                 return actions.join('');
                             }
                         }
                     }]
             };
             $.table.init(options);
         });
         initChildTable = function(index, row, $detail) {
             //debugger;
             var orderStatus = row.st;
             //alert(row.id);
             var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
             $(childTable).bootstrapTable({
                 url: prefix + "/listChild",
                 createUrl: prefix + "/add",
                 updateUrl: prefix + "/editSos/{id}",
                 removeUrl: prefix + "/remove",
                 exportUrl: prefix + "/export",
                 modalName: "修改发货数量",
                 method: 'post',
                 sidePagination: "server",
                 contentType: "application/x-www-form-urlencoded",
                 queryParams : {
                     mid: row.id
                 },
                 columns: [
                     {
                         field: 'mid',
                         title: '表头ID'
                     },
                     {
                         field: 'mcode',
                         title: '表头单号'
                     },
                     {
                         field: 'pcode',
                         title: '产品代码'
                     },
                     {
                         field: 'pname',
                         title: '产品名称'
                     },
                     {
                         field: 'pstd',
                         title: '产品规格'
                     },
                     {
                         field: 'punit',
                         title: '单位'
                     },
                     {
                         field: 'qty',
                         title: '订单数量'
                     },
                     {
                         field: 'sendqty',
                         title: '已发货数量'
                     },
                     {
                         field: 'unSendqty',
                         title: '未发货数量'
                     },
                     {
                         field: 'smemo',
                         title: '备注'
                     },
                     {
                         field: 'sts',
                         title: '状态'
                     }/*,
                     {
                         title: '操作',
                         align: 'center',
                         formatter: function(value, row, index) {
                             debugger;
                             if((orderStatus == "保存") || (orderStatus="审核")){

                                 var actions = [];
                                 /!*actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'22' + row.id + '\')"><i class="fa fa-edit"></i>修改发货数量</a> ');*!/
                                 actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="addSosSend(\'' + row.id + '\')"><i class="fa fa-edit"></i>添加发货记录</a> ');
                                 actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="viewSosSend(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看发货记录</a> ');
                                 return actions.join('');

                             }

                         }
                     }*/]
             });

         };

         function batchUpdate(id) {
             $.modal.open("批量修改发货数量", ctx+"erp/sos/view/"+id);
         }

         function viewSosSend(id) {
             $.modal.open("查看发货记录", ctx+"erp/sossend/view/"+id,"1100","500");
         }

         function addSosSend(id) {
             $.modal.open("添加发货记录", ctx+"erp/so/addSosSend/"+id,"800","300");
         }


         function closeso(id) {
             debugger;
             $.ajax({
                 type: "post",
                 url: ctx + "erp/so/closeSo?id="+id,
                 success: function(r) {
                     $.modal.msgSuccess("关闭成功");
                 }
             });
             $("#bootstrap-table").bootstrapTable('refresh', {
                 silent: true
             });
         }

         function openso(id) {
             debugger;
             $.ajax({
                 type: "post",
                 url: ctx + "erp/so/openSo?id="+id,
                 success: function(r) {
                     $.modal.msgSuccess("恢复订单成功");
                 }
             });
             $("#bootstrap-table").bootstrapTable('refresh', {
                 silent: true
             });
         }

         function review(id) {
             debugger;
             $.ajax({
                 type: "post",
                 url: ctx + "erp/so/reviewSo?id="+id,
                 success: function(r) {
                     $.modal.msgSuccess("审批成功");
                 }
             });
             $("#bootstrap-table").bootstrapTable('refresh', {
                 silent: true
             });
         }

         function disReview(id) {
             debugger;
             $.ajax({
                 type: "post",
                 url: ctx + "erp/so/disReviewSo?id="+id,
                 success: function(r) {
                     $.modal.msgSuccess("撤销成功");
                 }
             });
             $("#bootstrap-table").bootstrapTable('refresh', {
                 silent: true
             });
         }

         function senditem(id) {
             debugger;
             $.ajax({
                 type: "post",
                 url: ctx + "erp/so/sendOrder?id="+id,
                 success: function(r) {
                     debugger;
                     if(r.msg == "订单审核之后才能发货"){
                         $.modal.alertWarning("订单审核之后才能发货");
                         $.table.refresh();
                     }else{
                         $.modal.msgSuccess("发货成功");
                         $.table.refresh();
                     }
                 }
             });
             $("#bootstrap-table").bootstrapTable('refresh', {
                 silent: true
             });
         }

         // 直接返回获取
         var data = [{"v":"taobao","n":"淘宝","s":[{"v":"tm","n":"天猫"},{"v":"jhs","n":"聚划算"}]},{"v":"jd","n":"京东","s":[{"v":"jdcs","n":"京东超市"},{"v":"jdsx","n":"京东生鲜"}]}];
         $('#element').cxSelect({
             selects: ['type', 'router'],
             jsonValue: 'v',
             data: data
         });

         $('#st').selectpicker('refresh');
         //render方法强制重新渲染引导程序 - 选择ui,如果当您编程时更改任何相关值而影响元素布局，这将非常有用。
         $('#st').selectpicker('render');

     </script>
     <div th:include="include :: footer"></div>


</body>
</html>